<?php
class EmagineIT
{
	function getRssFeeds($type)
	{
		require_once('rss/xml_domit_rss.php');	
		$feeds = $type;
		//echo count($feeds);
		$cacheDir = 'cache/';
		$cacheTime = 3600;
		$stories = array();
		//echo $feeds;
		/*foreach ($feeds as $feed) 
		{*/
			//echo "dasfdsafdsfadf";
			//print_r($feed);
			$rssdoc = new xml_domit_rss_document($feeds, $cacheDir, $cacheTime);
		//	echo $rssdoc ;
			$totalChannels = $rssdoc->getChannelCount();
			for ($i = 0; $i < $totalChannels; $i++) 
			{
				$currChannel =& $rssdoc->getChannel($i);
				$ctitle = $currChannel->getTitle();
				$cimage = $cimageurl = "";
				$cimage = $currChannel->getImage();
				if (!empty($cimage))
					$cimageurl = $cimage->getUrl();
	
				//get total number of items
				$totalItems = $currChannel->getItemCount();
				
				//loop through each item
				for ($j = 0; $j < $totalItems; $j++) 
				{
					$currItem =& $currChannel->getItem($j);
					
					$date = strtotime($currItem->getPubDate());
					if (!$date)
						$date = strtotime(str_replace(substr($currItem->getPubDate(), -6, 6), "Z", $currItem->getPubDate()));
					if (!$date)
						$date = time();
					$stories[] = array('date' => date("Y-m-d H:i:s", $date),
										'title' => $currItem->getTitle(),
										'link' => $currItem->getLink(),
										'description' => strip_tags($currItem->getDescription()),
										'description_html' => $currItem->getDescription(),
										'PK_ID' => $j,
										'feed_title' => $ctitle,
										'image' => $cimageurl);
				}
			}
		
		/*}*/
		return $stories;
	}
	function rss_proper_html($rsshtml)
	{
		$rsshtml = str_replace("&","&amp;",$rsshtml);
		$rsshtml = str_replace("\"","&quot;",$rsshtml);
		$rsshtml = str_replace("<","&lt;",$rsshtml);
		$rsshtml = str_replace(">","&gt;",$rsshtml);
		$rsshtml = str_replace(" ","&nbsp;",$rsshtml);
		$rsshtml = str_replace(" ","&",$rsshtml);
		return $rsshtml;
	}
	function language_converter($divid,$text,$lang)
	{
		$convert = "<script type=\"text/javascript\"> google.load(\"language\", \"1\");
		function initialize() {
      google.language.translate(\"".$text."\", \"en\", \"".$lang."\", function(result) {
        if (!result.error) {
          var container = document.getElementById(\"".$divid."\");
          container.innerHTML = result.translation;
        }
      });
    }google.setOnLoadCallback(initialize);</script>";
		return $convert;
	}
	
	
	//$page_from_db 		= $obj->display_page($_REQUEST["page"], $conn);
	
	function add_user($created, $modified, $first_name,  $last_name, $middle_name, $login, $password, $gender_id, $dob, $about_me, $address, $city_id, $state_id, $country_id, $zip_code, $user_email, $user_mobile, $user_phone, $user_intrst_cat, $user_dp_lower, $user_dp_upper, $user_status, $conn )
	{
	  $sql = "INSERT INTO user_profiles ( created , modified , first_name, last_name ,middle_name , login , password ,gender_id , dob , about_me , address , city_id , state_id, country_id, zip_code, user_email, user_mobile, user_phone, user_intrst_cat, user_dp_lower, user_dp_upper, user_status) VALUES ('".$created."','".$modified."', '".$first_name."', '".$last_name."', '".$middle_name."', '".$login."','".$password."','".$gender_id."','".$dob."', '".$about_me."' , '".$address."' , '".$city_id."','".$state_id."', '".$country_id."', '".$zip_code."', '".$user_email."', '".$user_mobile."',  '".$user_phone."',  '".$user_intrst_cat."',  '".$user_dp_lower."', '".$user_dp_upper."', '1')";
	
	
	mysql_query($sql, $conn) or die(mysql_error());
	
	
	
	}
	
	
	
	////////////////////////////////////////////////
	
	function display_page($physical_name, $conn , $where = NULL )
	{
	  $sql = "SELECT * FROM contents WHERE page_physical_name='".$physical_name."' and status = 1 ".$where;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  $row = mysql_fetch_array($res);

	  return $row;
	}
	
	function display_child_page($physical_name, $conn , $where = NULL )
	{
	  $sql = "SELECT * FROM child_contents WHERE page_physical_name='".$physical_name."' and status = 1 ".$where;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  $row = mysql_fetch_array($res);
	  return $row;
	}
	function display_page_pressrelease($limit, $conn , $type , $where = NULL )
	{
	  $sql = "SELECT * FROM news WHERE ntype ='".$type."' and nstatus = 1 order by orderid LIMIT 0,".$limit."";
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  return $res;
	}
	function display_page_pressrelease_all($conn , $type , $where = NULL )
	{
	  $sql = "SELECT * FROM news WHERE ntype ='".$type."' and nstatus = 1 order by orderid";
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  return $res;
	}
	function display_pressrelase_page($physical_name, $conn , $where = NULL )
	{
	  $sql = "SELECT * FROM news WHERE page_physical_name='".$physical_name."' and nstatus = 1 ".$where;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  $row = mysql_fetch_array($res);
	  return $row;
	}
	
	
	function display_news_main_info()
	{
	  $sql = "SELECT * FROM news WHERE 1 and nstatus = 1 and main = 1";
	  $res = mysql_query($sql) or die(mysql_error());
	  $row = mysql_fetch_array($res);
	  return $row;
	}
	
	
	function display_password_protected($physical_name, $conn , $where = NULL )
	{
	  $sql = "SELECT * FROM contents WHERE page_physical_name='".$physical_name."' and password_protected = '1' ".$where;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  $row = mysql_num_rows($res);
	  return $row;
	}
	function display_page_type($physical_name, $conn , $type , $where = NULL )
	{
	  $sql = "SELECT * FROM news WHERE page_physical_name ='".$physical_name."' and nstatus = 1 and ntype = '".$type."' ".$where;
//	  print $sql;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  $row = mysql_fetch_array($res);
//	  echo "TEST:- ".$row['cont_header'];
	  return $row;
	}
	
	
	function display_page_type_active($conn , $type , $where = NULL )
	{
	  $sql = "SELECT * FROM news WHERE ntype = '".$type."' and nstatus = 1 ".$where;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  return $res;
	}
	function display_main_type($conn , $type , $where = NULL )
	{
	  $sql = "SELECT * FROM news WHERE ntype = '".$type."' and nstatus = 1 and main = 1 ".$where;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  $row = mysql_fetch_array($res);
	  return $row;
	}
	
	function display_main_image_type_size($image)
	{
	  list($width, $height, $type, $attr) = getimagesize("images/gallery/thumbs/".$image);
	  if($height > $width)
	  {
	  	$height = "3";
	  }
	  else
	  {
	  	$height = "40";
	  }
	  return $height;
	}
	
	function display_page_physical_name($conn , $type , $where = NULL )
	{
	  $sql = "SELECT * FROM news WHERE ntype = '".$type."' and nstatus = 1 ".$where;
//	  print $sql;
	  $res = mysql_query($sql, $conn) or die(mysql_error());
	  while($row = mysql_fetch_array($res))
	  {
		$page_title = $row["page_physical_name"];
		break;
	  }
	  //echo $page_title;
	  return $page_title;
	}
	function encrypt($plain_text) {
	$key = 'waqas';
	$plain_text = trim($plain_text);
	$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
	$c_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT, $iv);
	return trim(chop(base64_encode($c_t)));
	}
	
	function decrypt($c_t) {
	$key = 'waqas';
	$c_t =  trim(chop(base64_decode($c_t)));
	$iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
	$p_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
	return trim(chop($p_t));
	}
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
	{
	  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
	
	  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
	
	  switch ($theType) {
		case "text":
		  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
		  break;    
		case "long":
		case "int":
		  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
		  break;
		case "double":
		  $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
		  break;
		case "date":
		  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
		  break;
		case "defined":
		  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
		  break;
	  }
	  return $theValue;
	}    
}